home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / Amiga_Mail_Vol1 / IFF / ILBM-view < prev    next >
Encoding:
Text File  |  1999-10-27  |  8.0 KB  |  204 lines

  1. (c)  Copyright 1989-1999 Amiga, Inc.   All rights reserved.
  2. The information contained herein is subject to change without notice, and 
  3. is provided "as is" without warranty of any kind, either expressed or implied.  
  4. The entire risk as to the use of this information is assumed by the user.
  5.  
  6.  
  7.            Intro to IFF Amiga ILBM Files and Amiga Viewmodes
  8.  
  9.  
  10. The IFF, or Interchange File Format, for graphic images on the Amiga
  11. is called FORM ILBM (InterLeaved BitMap).  It follows a standard
  12. parsable IFF format.
  13.  
  14.  
  15. Sample hex dump of beginning of an ILBM:
  16.  
  17.  Important note - you can NOT ever depend on any particular ILBM chunk
  18.  being at any particular offset in the file!  IFF files are composed,
  19.  in their simplest form, of chunks within a FORM.  Each chunk starts
  20.  with a 4-letter chunk ID, followed by a 32-bit length for the rest of 
  21.  the chunk.  When you parse an IFF file, skip past unneeded or unknown 
  22.  chunks by seeking their length (+1 if odd length) to the next 4-letter 
  23.  chunk ID.
  24.  
  25. 0000: 464F524D 00016418 494C424D 424D4844    FORM..d.ILBMBMHD
  26. 0010: 00000014 01400190 00000000 06000100    .....@..........
  27. 0020: 00000A0B 01400190 43414D47 00000004    .....@..CAMG....
  28. 0030: 00000804 434D4150 00000030 001000E0    ....CMAP...0....
  29. 0040: E0E00000 20000050 30303050 50500030    .... ..P000PPP.0
  30. 0050: 90805040 70707010 60E02060 E06080D0    ..P@ppp.`. `.`..
  31. 0060: A0A0A0A0 90E0C0C0 C0D0A0E0 424F4459    ............BODY
  32. 0070: 000163AC F8000F80 148A5544 2ABDEFFF    ..c.......UD*...  etc.
  33.  
  34.  
  35.  
  36. Interpretation:
  37.  
  38.       'F O R M' length  'I L B M''B M H D'<-start of BitMapHeader chunk
  39. 0000: 464F524D 00016418 494C424D 424D4844    FORM..d.ILBMBMHD
  40.  
  41.        length  WideHigh XorgYorg PlMkCoPd <- Planes Mask Compression Pad
  42. 0010: 00000014 01400190 00000000 06000100    .....@..........
  43.  
  44.       TranAspt PagwPagh 'C A M G' length  <- start of C-AMiGa View modes chunk
  45. 0020: 00000A0B 01400190 43414D47 00000004    .....@..CAMG....
  46.  
  47.       Viewmode 'C M A P' length   R g b R <- Viewmode 800=HAM | 4=LACE 
  48. 0030: 00000804 434D4150 00000030 001000E0    ....CMAP...0....
  49.  
  50.        g b R g  b R g b  R g b R  g b R g <- Rgb's are for reg0 thru regN
  51. 0040: E0E00000 20000050 30303050 50500030    .... ..P000PPP.0
  52.  
  53.        b R g b  R g b R  g b R g  b R g b
  54. 0050: 90805040 70707010 60E02060 E06080D0    ..P@ppp.`. `.`..
  55.  
  56.        R g b R  g b R g  b R g b 'B O D Y' 
  57. 0060: A0A0A0A0 90E0C0C0 C0D0A000 424F4459    ............BODY
  58.  
  59.        length   start of body data        <- Compacted (Compression=1 above)
  60. 0070: 000163AC F8000F80 148A5544 2ABDEFFF    ..c.......UD*...
  61. 0080: FFBFF800 0F7FF7FC FF04F85A 77AD5DFE    ...........Zw.].  etc.
  62.  
  63.  
  64. The CAMG Viewmode codes are HIRES=0x8000, LACE=0x4, HAM=0x800  and
  65. HALFBRITE=0x80.
  66.  
  67.  
  68.  
  69. Interpreting ILBMs
  70.  
  71.       
  72. ILBM is a fairly simple IFF FORM.  All you really need to deal with
  73. to extract the image are the following chunks:
  74.  
  75.    BMHD - Information about the size, depth and compaction method.
  76.           (See interpreted hex dump above.)
  77.  
  78.    CAMG - Optional Amiga viewmodes chunk.
  79.           Most HAM and HALFBRITE ILBMs should have this chunk.  If no
  80.           CAMG chunk is present, and image is 6 planes deep, assume
  81.           HAM and you'll probably be right.  Some Amiga viewmodes
  82.           flags are HIRES=0x8000, LACE=0x4, HAM=0x800, HALFBRITE=0x80.
  83.  
  84.    CMAP - RGB values for color registers 0 to n.
  85.           (Each component left justified in a byte.)
  86.  
  87.    BODY - The pixel data, stored in an interleaved fashion as follows
  88.           (Note that each line is individually compacted if BMHD 
  89.            Compression = 1):
  90.  
  91.              plane 0 scan line 0
  92.              plane 1 scan line 0
  93.              plane 2 scan line 0
  94.              ...
  95.              plane n scan line 0
  96.              plane 0 scan line 1
  97.              plane 1 scan line 1
  98.              etc.
  99.  
  100. There are two ther chunks to watch out for - AUTH Author chunks and (c) 
  101. Copyright chunks.  Preserve any copyright information if you rewrite the 
  102. ILBM.
  103.  
  104.  
  105.  
  106. Body Compression
  107.  
  108.  
  109. The BODY contains pixel data for the image.  Width, height, and depth
  110. (i.e. the number of bit-planes) are specified in the BMHD.
  111. If the BMHD Compression byte is 0, then the scan line data is not compressed.
  112. If Compression=1, then each scan line is individually compressed as follows:
  113.  
  114.    o More than 2 bytes the same stored as BYTE code value n from  -1 to -127 
  115.      followed by byte to be repeated (-n) + 1 times.
  116.  
  117.    o Varied bytes stored as BYTE code n from 0 to 127 followed by n+1 bytes 
  118.      of data.
  119.  
  120.    o The byte code -128 is a NOP.
  121.  
  122.  
  123.  
  124. Interpreting the Scan Line Data:
  125.  
  126. If the ILBM is not HAM or HALFBRITE, then after parsing and uncompacting
  127. if necessary, you will have N planes of pixel data.  The color register
  128. used for each pixel is specified by looking at each pixel through the 
  129. planes.  I.e. if you have 5 planes, and the bit for a particular pixel is 
  130. set in planes 0 and 3:
  131.  
  132.        PLANE     4 3 2 1 0
  133.        PIXEL     0 1 0 0 1
  134.  
  135. then that pixel uses color register binary 01001 = decimal 9.
  136.  
  137. The RGB value for each color register is stored in the CMAP chunk of the 
  138. ILBM, starting with register 0.  Each register's RGB value are stored as
  139. one byte of R, one byte G, and one byte of B, with each component left
  140. justified in the byte.  I.e. Amiga R, G, and B components are each stored
  141. in the high nibble of a byte.
  142.  
  143.  
  144.  
  145. But - if the picture is HAM or HALFBRITE, it is interpreted differently.
  146. Hopefully, if the picture is HAM or HALFBRITE, the package that created 
  147. it also created a CAMG chunk.  Look at an ASCII dump of your file.  The
  148. chunks all start with a 4-character ASCII chunk ID.  If the picture is 6 
  149. planes deep and has no CAMG chunk, it is probably HAM.   If you see a 
  150. CAMG chunk in the file, the "CAMG" is followed by the 32-bit chunk length 
  151. and then the 32-bit Amiga Viewmode flags.  HAM pics will have the 0x800
  152. bit set in the CAMG chunk ViewModes.  HALBRITE pics will have the 0x80 
  153. bit set.
  154.  
  155.  
  156. How Amiga HAM Mode Works
  157.  
  158. To transport a HAM or HALFBRITE picture to another machine, you must
  159. understand how HAM and HALFBRITE work on the Amiga.
  160.  
  161. Amiga HAM (Hold and Modify) mode lets the Amiga display all 4096 RGB
  162. values.  In HAM mode, the bits in the two last planes describe an R G or
  163. B modification to the color of the previous pixel on the line to create
  164. the color of the current pixel.  So a 6-plane HAM picture has 4 planes
  165. for specifying absolute color pixels.  This  gives up to 16 absolute colors
  166. which would be specified in the ILBM CMAP chunk.  The bits in the last
  167. two planes are color modification bits.  These cause the Amiga, in HAM mode,
  168. to take the RGB value of the previous pixel, substitute the 4 bits in 
  169. planes 0-3 for the previous color's R G or B component and then display the 
  170. result at the current pixel.  If the first pixel of a scan line is a 
  171. modification pixel, it modifies the RGB value of the border color 
  172. (register 0).  The color modification bits in the last two planes 
  173. (planes 4 and 5) are interpreted as follows:
  174.  
  175.    00 - no modification.  Use planes 0-3 as normal color register index
  176.    10 - hold previous, replacing Blue component with bits from planes 0-3 
  177.    01 - hold previous, replacing Red component with bits from planes 0-3
  178.    11 - hold previous. replacing Green component with bits from planes 0-3
  179.  
  180.  
  181.  
  182. How Amiga HALFBRITE mode works:
  183.  
  184.    This one is simpler.  In HALFBRITE mode, the Amiga interprets the
  185. bit in the last plane as HALFBRITE modification - the bits in the other
  186. planes are treated as normal color register numbers. The RGB values for 
  187. each color register are specified in the CMAP chunk.  If the bit in the 
  188. last plane is set to one, then that pixel is displayed at half brightness. 
  189. This can provide up to 64 absolute colors.
  190.  
  191.  
  192. Other Notes
  193.  
  194. Amiga ILBM images must be a even number of bytes wide.  Smaller
  195. images, such as brushes, are padded to an even byte width.
  196.  
  197. ILBMs created with Electronic Art's Deluxe Paint II on the Amiga are 
  198. compatible with IBM version of DPaintII.  You may have to use a '.lbm' 
  199. filename extension on an IBM.  The ILBM graphic files may be transferred 
  200. between the two machines or between the Amiga and IBM sides of an A2000 
  201. equipped with a CBM Bridgeboard. 
  202.  
  203.  
  204.